#ifndef RTC_H
#define RTC_H

#include <stdint.h>
#include <stdbool.h>
#include "prj_typedef.h"
//#define REBOOT_REASON_IOS_VERSION_SWITCH
//#define REBOOT_REASON_OTA
//#define REBOOT_REASON_POWER_DOWN
//#define REBOOT_REASON_WDT
#define REBOOT_REASON_NORMAL_MODE 0
#define REBOOT_REASON_IOS_VERSION_SWITCH 0x5555AAAA
#define REBOOT_REASON_ERROR_CHECK 0xA5A5A5A5
#define REBOOT_REASON_FIRMWARE_BURNING 0x5A5A5A5A
#define REBOOT_REASON_CCCD_FAILD 0xAA55AA55
#define REBOOT_REASON_CMD_REBOOT 0x55AA55AA

typedef enum
{
    SPORT_ALERT_ENABLE_TYPE_SPORT_TIME,
    SPORT_ALERT_ENABLE_TYPE_DIST,
    SPORT_ALERT_ENABLE_TYPE_CALORIE,
    SPORT_ALERT_ENABLE_TYPE_HR,
} sport_alert_enable_type_t;

void RTCInit(void);
void RTCUpdate(uint32_t seconds);
uint32_t RTCGetSeconds(void);
extern sys_cfg_data_t m_sys_cfg_data;
void m_ble_time_out_disconnect_check(uint32_t seconds);

bool if_time_hour_system_12(void);
void time_hour_system_set(uint8_t type);

bool horologe_display_get_enable(void);
void horologe_display_set_enable(uint8_t enable);

void m_rtc_reset(void);
void m_reboot_value_set(uint32_t value);
uint32_t m_reboot_value_get(void);
void m_system_restart_reason(void);
void time_hour_system_init(void);

void rtc_timer_start(void);
void rtc_timer_stop(void);

uint8_t hr_get_default_wear_value(void);
void hr_set_default_wear_value(uint8_t value);

uint8_t home_page_type_get(void);
void home_page_type_set(uint8_t type);
void home_page_type_switch(void);

void syscfg_set_heart_auto_measure(bool enable);
bool syscfg_is_heart_auto_measure_enabled(void);

void system_config_set_km_mi(uint8_t km0_mi1);
uint8_t system_config_get_km_mi(void);

void system_config_set_gender(uint8_t gender);
uint8_t system_config_get_gender(void);

void system_config_set_age(uint8_t age);
uint8_t system_config_get_age(void);

void system_config_set_height(uint8_t height);
uint8_t system_config_get_height(void);

void system_config_set_weight(uint8_t weight);
uint8_t system_config_get_weight(void);

void system_config_set_lcd_auto_off_ms(uint16_t lcd_auto_off_ms);
uint16_t system_config_get_lcd_auto_off_ms(void);

void system_cfg_language_set(uint8_t type);
uint8_t system_cfg_language_get(void);

void set_scan_mode(Scan_mode scan_mode);
void set_warning_distance(int cm);

//音乐控制
// uint8_t music_ctrl_get_onoff(void);
// void music_ctrl_set_onoff(uint8_t onoff);
// void music_ctrl_state_switch(uint8_t flag);
void music_ctrl_set_sub_state(uint8_t state);
// extern bool is_music_start;
typedef enum __music_ctrl_action_t
{
    music_ctrl_action_start_stop,
    music_ctrl_action_previous,
    music_ctrl_action_next,
} music_ctrl_action_t;
void music_ctrl_action(music_ctrl_action_t action);
uint8_t music_ctrl_get_sub_state(void);
void media_player_control(uint8_t control);

//用户首页
void system_config_set_user_homepage_cfg(uint8_t select_data_type, uint8_t bg_img_diaphaneity);
uint8_t system_config_get_user_homepage_cfg_data_type(void);
uint8_t system_config_get_user_homepage_cfg_img_diaphaneity(void);
// void system_user_home_page_init(void);
// void system_user_home_page_set(uint8_t type);

//目标设置
void system_config_set_target(uint32_t target_step, uint32_t target_calorie, uint32_t target_dist);
uint32_t system_config_get_target_step(void);
uint32_t system_config_get_target_calorie(void);
uint32_t system_config_get_target_dist(void);
uint32_t system_config_get_target_sport_time(void);
uint32_t system_config_get_target_sleep_time(void);
//新增的目标设置
void system_config_set_target2(int target_sport_time, int target_sleep_time, uint8_t store_flash);
uint8_t system_config_get_sport_alert_enable(sport_alert_enable_type_t type);
void system_config_switch_sport_alert_enable(sport_alert_enable_type_t type);
// AGPS开关
void sys_cfg_agps_syn_set(uint8_t enable);
bool sys_cfg_agps_syn_if_enable(void);

/**
 * @brief 获取utc时间
 *
 * @return uint32_t
 */
uint32_t rtc_get_utc(void);
uint32_t rtc_get_zero_utc(void);
uint32_t rtc_get_zero_time(uint32_t time);

// int system_config_get_height(void);
// int system_config_get_age(void);

relax_option_time_t get_relax_option_time(void);
relax_option_shock_t get_relax_option_shock(void);
int get_metronome_hz(void);

void set_relax_option_time(relax_option_time_t option_time);
void set_relax_option_shock(relax_option_shock_t option_shock);
void set_metronome_hz(int);

void set_manual_sea_level_pressure(float);
float get_manual_sea_level_pressure(void);

void set_auto_sea_level_pressure(float);
float get_auto_sea_level_pressure(void);

altitude_calibration_t get_altitude_calibration_option(void);
void set_altitude_calibration_option(altitude_calibration_t option);
/**
 * @brief Get the heart rate level object
 *
 * @param heart
 * @return int 0-4
 */
int get_heart_rate_level(int heart);
int get_target_heart_rate_level(int heart, int level, int target_level);

void set_pressure_offset(float pressure_offset);
float get_pressure_offset(void);
void system_config_store_flash(void);
void set_ignore_infrared(bool value);
void unix_ts_to_band_ts(uint32_t unix_ts, uint32_t *p_band_ts);
#endif
